import Vuex from 'vuex'
import Vue from 'vue'

Vue.use(Vuex)
//模块化开发，这可以写成方法属性统一的对象了
const oldOption = {
  namespaced:true,
  actions: {
    add(context, value) {
      console.log('actions--add', context, value)
      context.commit('ADD', value)
    }
  },
  mutations: {
    ADD(state, value) {
      console.log('mutations-ADD', value)
      state.sum += value
    }
  },
  state: {
    sum: 0, sname: '老杨'
  },
  getters: {
    bigSum: function (state) {
      return state.sum * 10
    }
  }
}

const stuOption = {
  namespaced:true,
  actions: {  },
  mutations: {  },
  state: {
    student: {
      name:'张三',
      age:19
    }
  },
  getters: {
    info: function (state) {
      return state.student.name + state.student.age
    }
  }
}

export default new Vuex.Store({
 modules:{
   oldOption,stuOption
 }
});

